import { siteData } from './mysql-data'
const { $fn }  = window
const Index = ({ database, table_name, data }) => {
	const config = {
		modal:{
			title 	: <span>修改字段【<b className='c3 ar'>{data.Field}</b>】位置</span>,
			width 	: '35%'
		},
		form: {
			labelWidth: 's5',
			api: 'mysql/structure/mod_field',
			way:'put',
			infoApi : false,
			param: { database, table_name, ...data, change:false },
			data: [
				{ label: '字段名', name:'Field', disabled:1 },
				{ label: '数据类型', name:'Type', disabled:1 },
				{ label: '添加位置',	name: 'site',				type:'select', data:siteData, r:1, change: ({ value, ref })=>{
					$fn.getRow( config, 'site_name').hide = value !== 'after'
					ref.update()
				} },
				{ label: '选择位置',			name: 'site_name',			type:'select', data:[], listHeight:600, r:1, hide:1, change:({ value, ref }) =>{
					let Field = ref.getValue('Field')
					if(Field === value){
						$fn.msg.warning(`【${value}】的位置不能是本身`)
						setTimeout(()=>ref.setValue({ site_name:'' }))
					}
				} }
			]
		},
		onEnd: ({ update, tableRef }) => {
			$fn.getRow(config, 'site_name').data = tableRef.data().map( v => v.Field )
			update()
		}
	}
	return config
}
export default Index